/* uses de Casteljau to compute one coordinate value of a Bezier curve. Has to be called for each coordinate (x,y, and/or z) of a control polygon. Input: degree: degree of curve. coeff: array with coefficients of curve. t: parameter value. Output: coordinate value. */ float decas(degree,coeff,t) float coeff[]; float t; int degree; { int r,i; float t1; float coeffa[30]; /* an auxiliary array. Change dim. if too small*/ t1 = 1.0 - t; for(i=0; i<=degree; i++) coeffa[i]=coeff[i]; /* save input */ for (r=1; r<= degree; r++) for (i=0; i<= degree - r; i++) { coeffa[i]= t1* coeffa[i] + t * coeffa[i+1] ; } return (coeffa[0]); } main() { float t=0.5; int degree=3; float coordx[ ]={0, 0.5, 1, 3}; printf("Coordinata x= %6.4 f\n ", decas(degree, coordx, t) ); float coordy[ ]={0, 1, 1, 5}; printf("Coordinata y= %6.4 f\n ", decas(degree, coordy,t) ); float coordz[ ]={0, 3, 4, 8}; printf("Coordinata z= %6.4 f\n ", decas(degree, coordz,t) ); }